// Author: Domien Nowicki


#ifndef MAP_H
#define MAP_H

#include "Cell.h"

class Map
{
public:
    Map();
	Map(const Map& rhs);
    virtual ~Map();

	void DefaultResize();

	virtual void Resize(unsigned int newColumnCount, unsigned int newRowCount);

	unsigned int GetRowCount() const;
	unsigned int GetColumnCount() const;

	virtual void SetWallCell(unsigned int column, unsigned int row);
	virtual void SetEmptyCell(unsigned int column, unsigned int row);
	bool IsEmptyCell(unsigned int column, unsigned int row) const;
	virtual void SetTextureCell(unsigned int column, unsigned int row, Cell::Side side, unsigned int tindex, const Pixel& userColor);
	unsigned int GetTextureCell(unsigned int column, unsigned int row, Cell::Side side) const;

	const Cell& GetCell(unsigned int column, unsigned int row) const;
	Cell& GetCell(unsigned int column, unsigned int row);
	const Cell& operator()(unsigned int column, unsigned int row) const;
	Cell& operator()(unsigned int column, unsigned int row);

	void Clear();

protected:
	virtual Cell* NewCell(const Cell* copy, unsigned int column, unsigned int row);
	

private:
	
	void CopyCells(Cell** dstCellmap, Cell** srcCellmap, unsigned int newColumnCount, unsigned int newRowCount, unsigned int oldColumnCount, unsigned int oldRowCount);
	void InitCells(Cell** newcellmap, unsigned int newColumnCount, unsigned int newRowCount);
	void ClearCells(Cell** newcellmap, unsigned int newColumnCount, unsigned int newRowCount);
	
	unsigned int GetIndex(unsigned int column, unsigned int row) const;

	unsigned int rowCount, columnCount;
	Cell** cellmap;

	static const unsigned int DEFAULT_ROWCOUNT = 10, DEFAULT_COLUMNCOUNT = 10;
};

#endif // MAP_H
